package com.buer.storage.api;

import com.buer.storage.business.domain.UserEntity;
import com.buer.storage.business.service.UserEntityService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.holder.LoginUser;
import com.buer.storage.common.holder.LoginUserHolder;
import com.buer.storage.common.utils.BaseResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户
 */
@RestController("/user")
@Api(value = "用户相关", description = "用户相关")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserEntityService userEntityService;

    @ApiOperation(value = "用户列表")
    @PostMapping("/getUserList")
    @Auth
    public BaseResult getUserList(@RequestBody Map<String,Object> params) {
        LoginUser loginUserHolder = LoginUserHolder.getLoginUserHolder();
        params.put("userId",loginUserHolder.getUserId());
        PageInfo<UserEntity> entityList = userEntityService.getEntityList(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return BaseResult.build(ResultEnum.SUCCESS, result);

    }
}